package com.hmall.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmall.user.mapper.AddressMapper;
import com.hmall.user.pojo.Address;
import com.hmall.user.service.IAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AddressService extends ServiceImpl<AddressMapper, Address> implements IAddressService {
    @Autowired
    AddressMapper addressMapper;
    @Override
    public List<Address> getByUserId(Long userId) {
        //select * from tb_address where user_id=?
        //构造查询条件
        QueryWrapper<Address> wrapper = Wrappers.<Address>query()
                .eq("user_id", userId);
        //根据条件查询
        List<Address> list = addressMapper.selectList(wrapper);
        //返回结果
        return list;
    }

    @Override
    public Address add(Address address) {
        addressMapper.insert(address);
        return address;
    }

    @Override
    public void deleteById(Long id) {
        addressMapper.deleteById(id);
    }
}